<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">download</button>
    <script>
        const btn = document.getElementById('btn')
        btn.addEventListener('click', () => {
            fetch("http://localhost:7001/stream_download", {
                method: "POST"
                // 获取它的arrayBuffer结构
            }).then(res => res.arrayBuffer()).then(res => {
                // 1.转成blob
                const blob = new Blob([res], {
                    type: "image/jpg"
                })
                // 转成url
                const url = URL.createObjectURL(blob)
                console.log(url); // http://127.0.0.1:5500/27021272-fff7-4661-99a8-92db691ca63a
                // 创建a标签模拟点击
                const a = document.createElement("a");
                a.href = url;
                a.download = "1.jpg";
                a.click();
            })

        })
    </script>
</body>

</html>